<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<%--
  Created by IntelliJ IDEA.
  User: BF100233
  Date: 2016/9/22
  Time: 10:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>input</title>
</head>
<body>


<br>
<form:form action="${pageContext.request.contextPath}/emp" method="post" modelAttribute="employee">
    <form:errors path="*"></form:errors>
    <br>
    <c:if test="${!empty employee.id}">
        <form:hidden path="id"/>
        <input type="hidden" name="_method" value="PUT"/>
    </c:if>
    <c:if test="${empty employee.id }">
        LastName:<form:input path="lastName"/>
        <form:errors path="lastName"></form:errors>
    </c:if>
    <br>
    Email:<form:input path="email"/>
    <form:errors path="email"></form:errors>
    <%
        Map<String, String> genders = new HashMap<String, String>();
        genders.put("1", "FaMale");
        genders.put("0", "Male");
        request.setAttribute("genders", genders);
    %>
    <br>
    Gender:<form:radiobuttons path="gender" items="${genders }"/>
    <br>

    Department:<form:select path="department.id" items="${departments}"
                            itemLabel="departmentName" itemValue="id">
</form:select>
    <br>
    <!--
    1.数据类型转换
    2.数据类型格式化
    3.数据校验.
    1>.如何校验？ 注解的方式 JSR30311111
    ①.使用JSR303验证标准
    ②.加入 hibenate validator 验证框架
    ③.在 SpringMVC 配置文件中添加  <%--<mvc:annotation-driver>--%>
    ④.需要在 bean 的属性上添加对应的注解
    ⑤.在目标方法 bean 类型的前面添加 @Valid 注解
    2>.验证出错转向到哪一个页面？
    注意：需校验的 Bean 对象和其绑定结果对象或错误对象时成对出现的，它们之间不允许生命其他入参
    3>.错误消息？如何显示，如何把错误消息进行格式化
    -->
    Birth:<form:input path="birth"/>
    <form:errors path="birth"></form:errors>
    <br>
    Salary:<form:input path="salary"/>
    <form:errors path="salary"></form:errors>
    <br>
    <input type="submit" value="Submit"/>
</form:form>

</body>
</html>
